define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'robot_user/index' + location.search,
                    add_url: 'robot_user/add',
                    // edit_url: 'robot_user/edit',
                    // del_url: 'robot_user/del',
                    multi_url: 'robot_user/multi',
                    import_url: 'robot_user/import',
                    table: 'robotuser_list',
                    robot_url: 'robot_user/robot'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'robotUser',
                sortName: 'recordDate',
                fixedColumns: true,
                fixedRightNumber: 1,
                templateView: false,
                clickToSelect: false,
                search: false,
                showColumns: false,
                showToggle: false,
                showExport: false,
                showSearch: false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {
                            field: 'agentID',
                            title: __('Agent'),
                            searchList: Config.adminUserList,
                            defaultValue: $("#loginUserId").val(),
                        },
                        {field: 'robotUser', title: __('RobotID')},
                        {
                            field: 'recordDate',
                            title: __('Logtime'),
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.date
                        },
                        {field: 'followNum', title: __('Follownum'), operate: false},
                        {field: 'refollowNum', title: __('Number of follow back'), operate: false},
                        {field: 'videolikesNum', title: __('Number of likes on short videos'), operate: false},
                        {field: 'videocommetNum', title: __('Number of short video comments'), operate: false},
                        {
                            field: 'robotstatus',
                            title: __('Status'),
                            formatter: Table.api.formatter.status,
                            searchList: {0: '异常', 1: '正常', 9: '删除'},
                            operate: false
                        },
                        {
                            field:
                                'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'frequency',
                                    text: '频度设置',
                                    title:  __('Frequency settings'),
                                    classname: 'btn btn-xs btn-success btn-dialog btn-frequency frequency',
                                    refresh: true,
                                    url: "robot_user/frequency"
                                },
                                {
                                    name: 'stop',
                                    text: '账号停用',
                                    title: __('Account deactivation'),
                                    extend: 'data-toggle="tooltip"',
                                    classname: 'btn btn-xs btn-success btn-ajax btn-stop',
                                    refresh: true,
                                    confirm: function () {
                                        return '是否确定停用该账号？';
                                    },
                                    visible: function (row) {
                                        if (row.status != 9) {//判断显示隐藏 只有状态为待审核时展
                                            return true;
                                        } else {
                                            return false;
                                        }
                                    },
                                    url: "robot_user/stop"
                                },
                                {
                                    text: '查看关注详情',
                                    title: __('Check the following details'),
                                    classname: 'btn btn-xs btn-success btn-addtabs',
                                    url: "agentrobot_livestreamer_list/index"
                                },
                                {
                                    text: '查看回关详情',
                                    title: __('Check the following details'),
                                    classname: 'btn btn-xs btn-success btn-addtabs',
                                    url: "agentrobot_livestreamer_list/index"
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            // $(document).on('click', ".btn-stop", function () {
            //     var that = this;
            //     console.log(table.bootstrapTable('getOptions').pk)
            //     // Layer.confirm(__('Are you sure you want to truncate?'), function () {
            //     //     var url = "robot_user/stop";
            //     //     Fast.api.ajax(url, function () {
            //     //         Layer.closeAll();
            //     //         table.trigger("uncheckbox");
            //     //         table.bootstrapTable('refresh');
            //     //     }, function () {
            //     //         Layer.closeAll();
            //     //     });
            //     // });
            //     // return false;
            // });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        frequency: function () {
            Controller.api.bindevent();
        },
        robot: function () {
            Controller.api.bindevent();
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
